<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
${pu:reqSet('user', pu:user())}
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="<%=application.getContextPath() %>/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="<%=application.getContextPath() %>/js/jquery.datepick-zh-CN.js"></script>
<script src="<%=application.getContextPath() %>/js/jquery.tooltip.js" type="text/javascript"></script>

<link rel="stylesheet" href="<%=application.getContextPath() %>/css/jquery.tooltip.css" />
<link rel="stylesheet" type="text/css" href="<%=application.getContextPath() %>/css/smoothness.datepick.css" />
<link rel="stylesheet" type="text/css" href="<%=application.getContextPath() %>/css/validator.css" />
<script language="javascript">
	$().ready( function() {
		if($('#dialog').length==0){
			$('body').append('<div id="dialog"></div>');
		}
		$('#orderDtStParam').datepick({dateFormat:"yy-mm-dd"}); 
		$('#orderDtEdParam').datepick({dateFormat:"yy-mm-dd"});

		$("tr.tdDesc").tooltip();
		//updateOrderSt();
		$("#exportOrderList").click(function(){
			var chkRequired = new Array("orderIdParam","mobile","phone","recvadddress","prodIdParam","loginIdParam","receiverParam");
			var isValid = false;
			for (var i=0;i<chkRequired.length;i++) {
				var id = chkRequired[i];
				if ($.trim($("#"+id).val()) != "") {
					isValid = true;
					break;
				}
			}
			//if($.trim($("#prodIdParam").val())==""&& $.trim($("#loginIdParam").val())==""){
			//	alert("此功能必须要输入会员id或商品编号");
			if (!isValid) {
				alert("此功能必须输入以下任一栏位: \r\n订单编号 / 收件人手机号码 / 收件人固定电话 /\r\n 商品编号 / 收件人地址 / 会员id / 收件人");				
			}else{	
				//document.orderQuery.action='exportOrderList.do';
				$("#orderQuery").attr("action","exportOrderList.do");
				$("#orderQuery").submit();
			}	
		});
		$("#queryOrder").click(function(){
			$("#orderQuery").attr("action","query.do");
			$("#orderQuery").submit();
		});
		$("#phoneLike1").click(function(){
			if(this.checked){
				$("#phoneLike2").val('Y');
				
			}else{
				$("#phoneLike2").val('N');
			}
		});
		$("#recvadddressLike1").click(function(){
			if(this.checked){
				$("#recvadddressLike2").val('Y');
				
			}else{
				$("#recvadddressLike2").val('N');
			}
		});
		$(":input[id*=updOrdSt]").click(function(){
			var orderId = $(this).attr('id').split('_')[1];
			var orderStCode = $(this).attr('id').split('_')[2];
			<%--$.post("<%=application.getContextPath()%>/order/updOrdSt.do",{orderId:orderId,orderStCode:orderStCode},callback,"json");--%>
			location.href="/ecadmin/order/updOrdSt.do?orderId="+orderId+"&orderStCode="+orderStCode;
	
		});	
		
	});
	function customRange (){
		var startDt = $('#orderDtStParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt,maxDate: new Date(${today})}; 
	}

	//更新狀態
	//function updateOrderSt(){
		
	//}
			
</script>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br />
<h1>订单管理</h1>
<div class="f-link">
<yaodian100:checkPermission permissions="ROLE_ORD">
<a href="#" id="exportOrderList" title="此功能必须输入以下任一栏位: &#10;订单编号 / 收件人手机号码 / 收件人固定电话 /&#10; 商品编号 / 收件人地址 / 会员id / 收件人">汇出订单资料</a>
</yaodian100:checkPermission>
</div>
<br /><br /><br />
<div class="data-form"><s:form action="query.do" method="post" id="orderQuery">
	<b>订单编号：</b>
	<input name="orderIdParam" type="text" id="orderIdParam"
		value="${orderIdParam}" size="20" maxlength="20">
	<b>收件人手机号码：</b>
	<input type="text" name="mobile" id="mobile" value="${mobile }" size="15" maxlength="15"/>	
	<b>收件人固定电话：</b>
	模糊查询:<input type="hidden" name="phoneLike" id="phoneLike2" value="N"/>
	<input type="checkbox" name="phoneLike_check" id="phoneLike1" value="Y" ${phoneLike=='Y'?'checked':'' }/>
	<input type="text" name="phone" id="phone" value="${phone }" size="15" maxlength="15"/>		
	<BR>
	<b>商品编号：</b>
	<input type="text" name="prodIdParam" id="prodIdParam" value="${prodIdParam }" size="10" maxlength="8"/>	
	<b>收件人地址：</b>
	模糊查询:<input type="checkbox" name="recvadddressLike_check" id="recvadddressLike1" value="Y" ${recvadddressLike=='Y'?'checked':'' }>
	<input type="hidden" name="recvadddressLike" id="recvadddressLike2" value="N" >
	<input type="text" name="recvadddress" id="recvadddress" value="${recvadddress }" size="50" />	
	<br>
	<b>订购日期：</b>
	<input name="orderDtStParam" type="text" id="orderDtStParam"
		value="${orderDtStParam}" size="10" maxlength="10">
    ~ <input name="orderDtEdParam" type="text" id="orderDtEdParam"
		value="${orderDtEdParam}" size="10" maxlength="10">
	会员id：<input name="loginIdParam" type="text" id="loginIdParam"
		value="${loginIdParam}" size="20" maxlength="20">
	<b>收件人：</b>
	<input type="text" name="receiverParam" id="receiverParam" value="${receiverParam }" size="10" maxlength="15"/>
	<BR>订单状态：<s:select label="订单状态" name="orderStParam" headerKey="" headerValue="全部"
		list="orderStMenu.options" listKey="key" listValue="value.name" />
	付款状态：<s:select label="付款状态" name="paymentStParam" headerKey="" headerValue="全部"
		list="paymentStMenu.options" listKey="key" listValue="value.name" />
	付款方式：<s:select label="付款状态" name="paymentTpParam" headerKey="" headerValue="全部"
		list="paymentTpMenu.options" listKey="key" listValue="value.name" />
	网站：<s:select label="订单来源" name="domainSrcParam" value="domainSrcParam" headerKey="" headerValue="全部"
		list="domainSrc.options" listKey="key" listValue="value.name" />
  <br>
  外部订单编号：<input name="outerOrderIdParam" type="text" id="outerOrderIdParam"
		value="${outerOrderIdParam}" size="20" >
 <b> 团购编号</b>：<input name="tuangouIdParam" type="text" id="tuangouIdParam"
		value="${tuangouIdParam}" size="10" >		
	<input type="button" value="搜寻" id="queryOrder" />	
</s:form>
</div>
<br/><br/><br/>
<s:if test="orders.size > 0">
	<yaodian100:pageutil link="query.do" pagerObj="${pager}" />
	<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th>订单号</th>
				<th>已同步</th>
				<th>订购日期</th>
				<th>订单状态<BR>
				付款状态</th>
				<th>付款方式</th>
				<th>购买商品</th>
				<th>总价</th>
				<th>订购人</th>
				<th>功能</th>
				<th>网站</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${orders}" var="orders" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''} tdDesc" id="tdDesc" title="订单编号:${orders.orderId}<BR>手机:${orders.receiverMobile}<BR>固定:${orders.receiverPhoneArea}-${orders.receiverPhone}-${orders.receiverExt}<BR>地址:${orders.receiverZip}${orders.receiverProvince}${orders.receiverCity}${orders.receiverArea}${orders.receiverAddr}<br>收件人:${orders.receiverName}<br>备注:${orders.memo}">
					<td><a href="view.do?orderId=${orders.orderId}" />${orders.orderId}</a><br>
					 <c:if test="${orders.orderType=='3'}">外部订单编号：${orders.outerOrderId}<br></c:if>
					 	<c-rt:if test="${not empty orders.tuangouId}">
					 		 <span class="icon-tuangou"><a href="javascript:doAR('<%=application.getContextPath()%>/tuangou/getTuangouInfo.do?tuangouId=${orders.tuangouId}', 'dialog');openDialog('团购说明',null,400,300);" title="${orders.tuangouName}">${orders.tuangouId}</a></span>    
				   		 <br>
				    	</c-rt:if>
					<c:if test="${orders.receiverTp=='30'}">
					<img src="/images/daphne/daphne.gif">
					</c:if>
					</td>
					<td>${orders.sync }</td>
					<td><fmt:formatDate value="${orders.orderDt}"
						pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>${orderStMenu.options[orders.orderSt].name}<BR>
					${paymentStMenu.options[orders.paymentSt].name}</td>
					<td>${paymentTpMenu.options[orders.paymentTp].name}</td>
					<td style="text-align:left"><c:forEach items="${orders.orderProduct}" var="oproduct"
						varStatus="rowdetail_index">
					${rowdetail_index.count > 1 ? '<BR>' : ''}${oproduct.prodName}${oproduct.prodSpecName}
					(${oproduct.qty}X${oproduct.unitPrice}=${oproduct.amount})${logisticStMenu.options[oproduct.logisticSt].name}
					<c:if test="${oproduct.returnQty > 0}">
							<BR>
							<B><font color=#ff3300>退:${oproduct.returnQty}\
							${returnStMenu.options[oproduct.returnSt].name}</font></B>
						</c:if>
						
						
						<br/>
						<br/>
						<c-rt:forEach items="${oproduct.applyCampaigns}" var="ac">
	          	
	          	<p>
	          	<c-rt:if test="${ac.active}">
	          		<span class="type-4" style="color:red">优惠</span>
	          	</c-rt:if>
	          	<c-rt:if test="${!ac.active}">
	          		<span class="type-6"  style="color:gray">优惠</span>（不符合）
	          	</c-rt:if>
	          <c-rt:if test="${ac.campaignUrl!=null}">
	          	<a target="_blank" class="a-red" href="${ac.campaignUrl }">${ac.campaignName }</a>
	          	</c-rt:if>
	          	<c-rt:if test="${ac.campaignUrl==null}">
	          	
	          	${pu:reqSet('pc', pu:get('com.yaodian100.ec.campaign.entity.Campaign', ac.campaignUuid)) }
	          	
	          	${ac.campaignName }
	          	
	          	</c-rt:if>
	          	</p>
	          	</c-rt:forEach>
						
						
					</c:forEach></td>
					<%--判斷訂單修改 --%>
					<c-rt:set var="canChgPaymentIfo" value="N"/>
		         	<c-rt:set var="canChgRecvInfo" value="N"/>
		         	<yaodian100:checkPermission permissions="GROUP_A-30-400-000">
		         	<c:choose>
			          <c:when test="${orders.paymentTp=='30' || orders.paymentTp=='60'}">
			          	<c:if test="${orders.orderSt=='00'}">
							<c-rt:set var="canChgPaymentIfo" value="Y"/>
		         			<c-rt:set var="canChgRecvInfo" value="Y"/>
						</c:if>
						<c:if test="${orders.orderSt=='20' }">
							<c-rt:set var="canChgRecvInfo" value="Y"/>
						</c:if>
			          </c:when>
			          <c:otherwise>
			          	<c:if test="${order.domainSrc!='www.yaodian100.com' && (order.orderSt=='00'||order.orderSt=='05')}">
		   					<c-rt:set var="canChgRecvInfo" value="Y"/>
						</c:if>
			          	<c:if test="${orders.paymentSt=='00' && orders.orderSt == '10'}">
			          		<c:choose>
							<c:when test="${orders.paymentTp=='80'}"><%--分期付款不能修改支付方式 --%>
								<c-rt:set var="canChgPaymentIfo" value="N"/>
							</c:when>
							<c:otherwise>
								<c-rt:set var="canChgPaymentIfo" value="Y"/>
							</c:otherwise>
							</c:choose>				          								
		         			<c-rt:set var="canChgRecvInfo" value="Y"/>
						</c:if>
						<c:if test="${orders.paymentSt=='10' && orders.sync=='false' && orders.orderSt == '20'}">
							<c-rt:set var="canChgRecvInfo" value="Y"/>
						</c:if>			          
			          </c:otherwise> 
			        </c:choose>
			        </yaodian100:checkPermission>
					<td><fmt:formatNumber value="${orders.amount - orders.bonus + orders.shipfare + orders.codFee + orders.installmentFee}" pattern="#####0.00"/></td>
					<td>${orders.memberName}</td>
					<td><a href="../cs/page.do?questionType=CommonQuestion&iamlazy=question&formType=workOrder&isProductQAA=false&memberId=${orders.memberId}&orderId=${orders.orderId}&channel=${pu:substring(user.group.code, 0, 1)=='C'?'CS':'SYS'}" target="_wo">开立工单</a>／<a href="../workOrder/page.do?iamlazy=list&orderId=${orders.orderId}&fromOrder=true" target="_wol">問答</a>
					<BR></BR>
					<c-rt:if test="${canChgRecvInfo=='Y'}"><a href="<c-rt:url value="/order/editReceiver.do?orderId=${orders.orderId}"/>" >修改收货人讯息</a><br></c-rt:if>
					<c-rt:if test="${canChgPaymentIfo=='Y'}"><a href="<c-rt:url value="/order/editPaymentTp.do?orderId=${orders.orderId}"/>" >修改支付方式</a><br></c-rt:if>
					<c-rt:if test="${orders.orderSt=='00'}">
						<c-rt:if test="${order.domainSrc!='www.yaodian100.com'}">
						   <input name="按鈕" type="button" value="人工處理" id="updOrdSt_${order.orderId}_05"/>
    				   		<input name="按鈕" type="button" value="等待配貨" id="updOrdSt_${order.orderId}_20"/>
						</c-rt:if>
						<c-rt:if test="${order.domainSrc=='www.yaodian100.com'}">
							<input name="按鈕" type="button" value="審核失敗" id="updOrdSt_${orders.orderId}_82"/>
							<c-rt:if test="${orders.paymentTp=='30' || orders.paymentTp=='60'}">	
								<input name="按鈕" type="button" value="等待配貨" id="updOrdSt_${orders.orderId}_20"/>
							</c-rt:if>
							<c-rt:if test="${orders.paymentTp=='10' || orders.paymentTp=='20'||orders.paymentTp=='40' || orders.paymentTp=='50'}">	
								<input name="按鈕" type="button" value="等待付款" id="updOrdSt_${orders.orderId}_10"/>
							</c-rt:if>	
						</c-rt:if>
					</c-rt:if>
					</td>
					<td>${domainSrc.options[orders.domainSrc].name}</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<yaodian100:pageutil link="query.do" pagerObj="${pager}" />
</s:if>
<br /><br /><br />
